#include <iostream>
#include <fstream>
#include "s-clique_free.cpp"
#include "IO.cpp"
#include <vector>
#include <boost/dynamic_bitset.hpp>
#include <string>
#include <ctime>

using namespace std;

int main(int argc, char** argv)
{

    if(argc != 3) {
        cout<<"Usage: ./filename 'graph_name' 's' - int"<<endl;
        return 0;
    }

    string filename( argv[1] );
    int s = atoi(argv[2]);

    if(s < 2) {
        cout<<"s must be a positive integer, and bigger than 1!"<<endl;
        return 0;
    }

    vector<dynamic_bitset<> > colorclasses;	//szinosztalyok
    vector<dynamic_bitset<> > graph;	//a graf
    clock_t start;
    clock_t end;

    int nodes, edges;

    //gráf beolvasása
    readgraph_bitset(filename, graph, nodes, edges);

    //kiszínezése
    start = clock();
    s_clique_coloring(graph, colorclasses, s);
    end = clock();
    cout<<"end coloring"<<endl;

    //színezés lementése
    savecolors(graph, colorclasses, filename, s);
printgraph_to_pbm(graph, filename, s);
    //gráf kinyomtatása
    sorting(graph, colorclasses);
    //printgraph_to_pbm(graph, filename, s);

    cout<<"Nodes: "<<nodes<<"\t Edges: "<<edges<<endl;
    cout<<"Number of "<<s<<" clique free colors: "<<colorclasses.size()<<endl;
    cout<<"Number of edge free colors: "<<colorclasses.size() * (s-1)<<endl;

    for(int i = 0; i < colorclasses.size(); ++i){
        cout<<i+1<<": ";
        for(int j = 0; j < colorclasses[i].size(); ++j){
            if(colorclasses[i][j])
                cout<<j+1<<',';
        }
        cout<<endl;
    }

    time_t rawtime;
    struct tm * timeinfo;
    char buffer[80];
    time (&rawtime);
    timeinfo = localtime(&rawtime);

    strftime(buffer,80,"%d-%m-%Y %I:%M:%S",timeinfo);
    string date(buffer);

    ofstream fout;
    fout.open("coloringLogFile.log", ofstream::app);
    fout.seekp(0, fout.end);
    fout<<date<<" - Graph: "<<filename<<"\ts: "<<s<<"\tsolution of coloring: ";
    fout<<colorclasses.size()<<"("<<colorclasses.size() * (s-1)<<")";
    fout<<"\tcoloring time: "<<diffclock(end, start)<<endl;


    return 0;
}
